//
//  MovieDetailsViewController.m
//  豆瓣
//
//  Created by Roach on 16/6/25.
//  Copyright © 2016年 lanou. All rights reserved.
//

#import "MovieDetailsViewController.h"
#import "MovieModel.h"
#import "UIImageView+WebCache.h"

@interface MovieDetailsViewController ()
@property (nonatomic, retain)NSString *movieId;
@property (nonatomic, retain)NSMutableArray *modelArray;
@property (nonatomic, retain)MovieModel *model;


@end

@implementation MovieDetailsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self config];
    [self values];
    [self createSubView];
}

- (void)config {
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = _movieModel.movieName;
    
}

- (void)values {
    
    self.modelArray = [[NSMutableArray alloc]init];
    self.movieId = [[NSString alloc]init];
    self.movieId = self.movieModel.movieId;
    
    NSString *str = [NSString stringWithFormat:@"m%@",self.movieId];

    NSString *path = [[NSBundle mainBundle]pathForResource:str ofType:@"txt"];
    NSData *data = [NSData dataWithContentsOfFile:path];

    NSError *error = nil;
   
    NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
   
    NSDictionary *resultArray = [dictionary objectForKey:@"result"];
   
    self.model = [[MovieModel alloc]init];
   
    [self.model setValuesForKeysWithDictionary:resultArray];
    
}


- (void)createSubView{
    
    UIScrollView *scroView =[[UIScrollView alloc]init];
    scroView.frame = CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds));
    scroView.contentSize = CGSizeMake(CGRectGetWidth(self.view.bounds),2000 );
    [self.view addSubview:scroView];
    
    
    
    NSURL *url = [NSURL URLWithString:self.model.poster];
    
    UIImageView *activitylconView = [[UIImageView alloc]init];
    [activitylconView sd_setImageWithURL:url];
    activitylconView.frame = CGRectMake(10, 30, 160, 200);
    [scroView addSubview:activitylconView];
    [activitylconView release];
    
    
    UILabel *timeLabel = [[UILabel alloc]initWithFrame:CGRectMake(200, 35, 200, 20) ];
    timeLabel.text = [NSString stringWithFormat:@"评分: %@", self.model.rating];
    timeLabel.font = [UIFont systemFontOfSize:20.0f];
    [scroView addSubview:timeLabel];
    
    
    
    UILabel *ownerLabel = [[UILabel alloc]initWithFrame:CGRectMake(300, 35, 230, 20)];
    ownerLabel.text = [NSString stringWithFormat:@"(%@评论)",self.model.rating_count];

    ownerLabel.font = [UIFont systemFontOfSize:20.0f];
    [scroView addSubview:ownerLabel];
  
    UILabel *categoryLabel = [[UILabel alloc]initWithFrame:CGRectMake(200, 70, 200, 20)];
    categoryLabel.text = self.model.release_date;
    categoryLabel.font = [UIFont systemFontOfSize:20.0f];
    [scroView addSubview:categoryLabel];
   
    UILabel *addressLabel = [[UILabel alloc]initWithFrame:CGRectMake(200, 90, 200, 40) ];
    addressLabel.text = self.model.runtime;
    addressLabel.font = [UIFont systemFontOfSize:20.0f];
    [scroView addSubview:addressLabel];
    
    UILabel *addressLabel1 = [[UILabel alloc]initWithFrame:CGRectMake(200, 120, 200, 40) ];
    addressLabel1.text = self.model.genres;
    addressLabel1.font = [UIFont systemFontOfSize:20.0f];
    [scroView addSubview:addressLabel1];
    
    
    UILabel *addressLabel2 = [[UILabel alloc]initWithFrame:CGRectMake(200, 150, 200, 40) ];
    addressLabel2.text = self.model.film_locations;
    addressLabel2.font = [UIFont systemFontOfSize:20.0f];
    [scroView addSubview:addressLabel2];
    
    
    UILabel *view = [[UILabel alloc]initWithFrame:CGRectMake(10, 250, 100, 50) ];
    view.text =@"制作人";
    view.font = [UIFont boldSystemFontOfSize:25.0f];
    [scroView addSubview:view];
   
    UILabel *contentView = [[UILabel alloc]initWithFrame:CGRectMake(10, 300, 400, 50) ];
    contentView.text = self.model.actors;
    contentView.font = [UIFont systemFontOfSize:17.0f];
    contentView.numberOfLines = 0;
    [scroView addSubview:contentView];
    
    UILabel *view1 = [[UILabel alloc]initWithFrame:CGRectMake(10, 350, 100, 50) ];
    view1.text =@"电影情节";
    view1.font = [UIFont boldSystemFontOfSize:25.0f];
    [scroView addSubview:view1];
    UILabel *contentView1 = [[UILabel alloc]initWithFrame:CGRectMake(10, 400, 400, 200) ];
    contentView1.text = self.model.plot_simple;
    contentView1.font = [UIFont systemFontOfSize:17.0f];
    contentView1.numberOfLines = 0;
    [scroView addSubview:contentView1];
    
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end

